package sel.me.sharding.learning.service;

import org.apache.commons.lang3.RandomUtils;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.support.TransactionTemplate;
import sel.me.sharding.learning.dao.OrderMapper;
import sel.me.sharding.learning.dao.UserMapper;
import sel.me.sharding.learning.entity.Order;

import java.util.List;

/**
 * @author shenenlu 2021年02月26日 下午19:46:00
 */
@Service
public class OrderService {

    @Autowired
    private OrderMapper orderMapper;

    @Autowired
    private UserMapper userMapper;

    @Autowired
    private TransactionTemplate transactionTemplate;

    @Transactional
    public void insert(){
        for(int i= 1; i <= 100; i++) {
//            if( i == 10 ){
//                throw new RuntimeException();
//            }
            SqlSessionTemplate s;
            Order o =new Order();
            o.setOrderId(i);
            o.setUserId(RandomUtils.nextInt(1,10));
            orderMapper.insertSelective(o);
        }
    }

    public List<Order> selectOrderList(){
        return orderMapper.selectAll();
    }
}
